/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;

/**
 * Thread that performs the actions when any buttons are pressed.
 * @author
 */
public class buttonThread extends Thread {

    private Robot mRobot997;
    private Joystick m_gigaware;


    /**
     * The constructor.
     * @param A reference to the 997 robot and its necessary objects.
     */
    public buttonThread(Robot robot) {
        mRobot997 = robot;
        m_gigaware = mRobot997.getGigaware();
    }

    public void run() {
        while (mRobot997.isOperatorControl() && mRobot997.isEnabled()) {
            // DO NOT PUT ANY  CODE THAT TALKS TO THE MOTORS IN THIS THREAD!!!
            // All motor code should be in the main thread.

            //ExtendedKickerSensor stuff
            if(mRobot997.extendedKicker == mRobot997.Extended) {
                Timer.delay(1);
                mRobot997.retractKicker();
            }

            //************Gigaware code******************
            // Third stick code is below.
            if (m_gigaware.getRawButton(8)) {
                mRobot997.performKick();
            }
            if (m_gigaware.getRawButton(6)) {
                mRobot997.performSoftKick();
            }

            // Latch the kicker.
            if (m_gigaware.getRawButton(1)) {
                mRobot997.driveLatchSolenoid(1);
                //Wait for button to be released.
                while (m_gigaware.getRawButton(1)) {
                    Thread.yield();
                }
            }
            //Unlatch the kicker.
            if (m_gigaware.getRawButton(2)) {
                mRobot997.driveLatchSolenoid(0);
                //Wait for button to be released.
                while (m_gigaware.getRawButton(2)) {
                    Thread.yield();
                }
            }

            // Flush the kicker.
            if (m_gigaware.getRawButton(4)) {
                mRobot997.driveShooterSolenoid(0);
                //Wait for button to be released.
                while (m_gigaware.getRawButton(4)) {
                    Thread.yield();
                }
            }

            //Charge the Kicker.
            if (m_gigaware.getRawButton(3)) {
                mRobot997.driveShooterSolenoid(1);
                //Wait for button to be released.
                while (m_gigaware.getRawButton(3)) {
                    Thread.yield();
                }
            }

            if (m_gigaware.getRawButton(9)) {
                mRobot997.switchBallHolder(mRobot997.Off);
                //wait for button to be released
                while (m_gigaware.getRawButton(9)) {
                    Thread.yield();
                }
            }else{
                if (m_gigaware.getRawButton(5)) {
                    mRobot997.switchBallHolder(mRobot997.Forward);
                    //Wait for button to be released.
                    while (m_gigaware.getRawButton(5)) {
                        Thread.yield();
                    }
                }
                if (m_gigaware.getRawButton(7)) {
                    mRobot997.switchBallHolder(mRobot997.Reverse);
                    //wait for button to be released
                    while (m_gigaware.getRawButton(7)) {
                        Thread.yield();
                    }
                }
            }

            Thread.yield();
            Timer.delay(0.0005);
        }
    }
}


